package com.leyou.search.web;

import com.leyou.common.vo.PageResult;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author fenglin
 * @date 2019/12/16 16:26
 */
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索商品数据
     *
     * @param searchRequest 请求参数
     * @return 当前页结果
     */
    @PostMapping("goods")
    public ResponseEntity<PageResult<GoodsDTO>> searchDoods(@RequestBody SearchRequest searchRequest){
        return ResponseEntity.ok(searchService.searchGoods(searchRequest));
    }

    /**
     * 搜索商品数据
     *
     * @param searchRequest 请求参数
     * @return 当前页结果
     */
    @PostMapping("filters")
    public ResponseEntity<Map<String,List<?>>> searchFilters(@RequestBody SearchRequest searchRequest){
        return ResponseEntity.ok(searchService.searchFilters(searchRequest));
    }
}
